package singleton;

/**
 * @author : yang.xp
 * @date : 2021/12/15 17:01
 * @description : 最合适的单例模式
 */
public class StaticSingleton {

    private int a;

    private StaticSingleton() {
        new Thread(() -> {
            try {
                Thread.sleep(1000);
            } catch (Exception e) {
                e.printStackTrace();
            }
            this.a = 100;
            System.out.println("构造方法：ccc");
        }).start();
        System.out.println("StaticSingleton is create " + a);
    }

    private static class SingletonHolder {
        private static StaticSingleton staticSingleton = new StaticSingleton();
    }

    public static StaticSingleton getInstance() {
        return SingletonHolder.staticSingleton;
    }
}
